//
// Created by dgy on 2022/11/7.
//
using namespace std;

#include <stack>
#include "iostream"
#include "vector"
class Solution{
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        if (pushed.size()==0)
            return true;
        stack<int> stack;
        int i=0,t=0;
        while(i<pushed.size()){
            stack.push(pushed.at(i));
            //cout<<stack.top()<<" ";
            while (!stack.empty()&&stack.top()==popped.at(t)){
                stack.pop();
                t++;
            }
            i++;
        }
        while (!stack.empty()&&stack.top()==popped.at(t)){
            stack.pop();
            t++;
        }
        if(stack.empty())
            return true;
        return false;
    }
};